nice_things/fs/realpath.sh
realpath
Since 0.3.0 · Source
import "{ realpath }" from nice_things/fs/realpath.sh
Synopsisrealpath <pathname>…
Configuration
–
Description
Print the resolved absolute path name; all but the last component must exist. This implementation tries to closely emulate the default behavior of the utilities with the same name in Busybox and GNU coreutils.
When many operands are passed and one fails to resolve, an error message is printed to log_error, and operation continues until the last operand is processed.
Note
This is not a pure sh implementation because it depends on the external
lsutility to read the target of symlinks. This works consistently because the output oflsis strictly specified in POSIX, but it means this function can be slower than most other functions in the framework. The slow branch is only reached when the last component of<pathname>is a symlink.
Options
–
Operands<pathname>: A path name.
Stdin
–
Stdout
A new-line separated list of absolute paths, one for each operand.
Stderrlog_error.
Exit status
0: Successful completion.23: Any<pathname>failed to resolve.
Abort
–
Usage examples
# Get the real path to the current program
program=$(realpath "$0")